<template>
	<div>
		<div>
			<MkCard>
				<BaseSearchForm 
					v-model:search-param="searchParam"
					@goBack="emit('goto-edit')"
					@search="search"
					@add="handleAdd"
					:isShowBack="false" 
					:isShowHistoryTitle="false"
					:isShowAdd="true"
				/>
			</MkCard>
			<MkCard>
				<MkTable height="600px" :data="filteredList" @row-dblclick="rowDbClick">
					<el-table-column label="ID" prop="id" />
					<el-table-column label="套餐代码" prop="code" />
					<el-table-column label="套餐名称" prop="name" />
					<el-table-column label="价格" prop="price" />
					<el-table-column label="套餐his收费编码" prop="hisCode" width="150px" />
					<el-table-column label="套餐类型" prop="type" />
					<el-table-column label="套餐分组" prop="group" />
					<el-table-column label="参数说明" prop="paramDesc" />
					<el-table-column label="检验结果时限/分" prop="paramDesc" />
					<el-table-column label="超时提醒时间/分" prop="paramDesc" />
					<el-table-column label="审核是否自动签名" prop="autoSign" />
					<el-table-column label="排序" prop="sort" />
					<MkColumnIsEnabled />
				</MkTable>
			</MkCard>
		</div>
		<!-- <EditDialog ref="editDialogRef" /> -->
		<Edit  ref="editRef"  @returnData="returnData"/>
	</div>
</template>
<script lang="ts" setup>
import Edit from './components/Edit.vue';
import { ref,onMounted } from 'vue';
// import EditDialog from './components/EditDialog.vue';
// const editDialogRef = ref();
const editRef = ref();
/**
 * 增加检验套餐分组
 */
//定义检索变量
const searchParam = reactive({
	keyword: undefined,
	startCreationTime: undefined,
	endCreationTime: undefined,
});
interface jilei {
  id: number;
	code: string;
  name: string;
  price: string;
  hisCode: string;
  type: string;
  group: string;
  paramDesc: string;
  autoSign: string;
  sort: string;
	isEnabled:boolean;
}
//假数据
const List =  ref<jilei[]>([{
	id: 1,
	code: '01',
	name: '张三',
	price: '12',
	hisCode: '001',
	type: '类型1',
	group: '分组1',
	paramDesc: '参数1',
	autoSign: '是',
	sort: '1',
	isEnabled:false
},{
	id: 1,
	code: '02',
	name: '李四',
	price: '13',
	hisCode: '002',
	type: '类型2',
	group: '分组2',
	paramDesc: '参数2',
	autoSign: '否',
	sort: '2',
	isEnabled:true
},{
	id: 1,
	code: '03',
	name: '王五',
	price: '12',
	hisCode: '003',
	type: '类型3',
	group: '分组3',
	paramDesc: '参数3',
	autoSign: '否',
	sort: '3',
	isEnabled:true
}]);

// 用于存储过滤后的结果
const filteredList = ref<jilei[]>([]);
//检索
const search = () => {
  const keyword = searchParam.keyword;

  // 如果没有关键字，返回全部数据
  if (!keyword) {
    filteredList.value = List.value;
    return;
  }
  filteredList.value = List.value.filter(item => {
    return (
      item.code.toLowerCase().includes(keyword) ||
      item.name.toLowerCase().includes(keyword) ||
      item.price.toLowerCase().includes(keyword)
    );
  });
};	
const emit = defineEmits(['goto-edit'])
const handleAdd = () => {
	editRef.value.openDrawerFn();
	//editDialogRef.value.showDialog();
};
const rowDbClick = (row: any) => {
	editRef.value.openDrawerFn();
  editRef.value.DataAssignment(row);
}
//修改页回显数据
const returnData = (data: any)=>{
	let index = List.value.findIndex(t => t.id == data.value.id)
	if(index != -1){
		filteredList.value[index] = data.value
	}
}
onMounted(() => {
  search();
});
defineOptions({
	name: 'InpItemSetMeal',
});
</script>
